-- add column TYPE
IF NOT EXISTS (SELECT * FROM sys.columns WHERE Name = N'TYPE' AND OBJECT_ID = object_id(N'[dbo].[Surveys]'))
BEGIN
	ALTER TABLE [dbo].[Surveys] ADD [TYPE] int NOT NULL DEFAULT 0
END
GO

-- add column DOCUMENT_ID
IF NOT EXISTS (SELECT * FROM sys.columns WHERE Name = N'DOCUMENT_ID' AND OBJECT_ID = object_id(N'[dbo].[SurveySessions]'))
BEGIN
	ALTER TABLE [dbo].[SurveySessions] ADD DOCUMENT_ID varchar(20) NULL

	ALTER TABLE [dbo].[SurveySessions] ALTER COLUMN CONVERSATION_GUID uniqueidentifier NULL

	ALTER TABLE [dbo].[SurveySessions] ADD CONSTRAINT [SurveySessions_check_DOCUMENT_ID_CONVERSATION_GUID] CHECK 
		((DOCUMENT_ID is not null) OR (CONVERSATION_GUID is not null))
END
GO
